package cn.dengta.webapp.trade.form;

import cn.dengta.common.validator.Check;
import cn.dengta.common.validator.Range;
import cn.dengta.context.model.WesKit;
import cn.dengta.context.web.RequestContextImpl;
import cn.dengta.webapp.base.form.BaseForm;
import cn.dengta.webapp.trade.entity.GiftLog;
import cn.dengta.webapp.user.model.BizType;
import lombok.*;
import me.codeplayer.util.*;

import static cn.dengta.context.model.TradeFormI18nKey.*;

/**
 * 用户送礼，保存电视墙礼物
 */
@Getter
@Setter
public class UserGiftForm extends BaseForm<GiftLog> {

	@Check(value = USER_GIFT_FORM_TO_USER_ID, required = false)
	@Range(min = 1)
	public Long toUserId;

	@Check(USER_GIFT_FORM_GIFT_ID)
	@Range(min = 1)
	Long giftId;

	@Check(USER_GIFT_FORM_GIFT_NUM)
	@Range(min = 1)
	Integer giftNum;

	/** 1=视频场景; 2=背包 */
	Integer type;

	/** 群id */
	Long groupId;
	/** 背包id */
	Long bagId;
	/** 1=引导 */
	Integer source;
	/** Ai标识 */
	Long aiId;
	/** 速配ID */
	Long speedId;

	public WesKit wesKit;

	@Setter(AccessLevel.NONE)
	public Long sendUserId;

	@Setter(AccessLevel.NONE)
	public Long liveId;

	@Setter(AccessLevel.NONE)
	public BizType bizType = BizType.CHAT;

	boolean checkLimit = false;

	@Override
	public void preHandle() {
		Assert.isTrue(!(this.toUserId == null && this.aiId == null));
		this.wesKit = RequestContextImpl.get().getWesKit();
	}

	public boolean checkBag() {
		return Cmp.ge(bagId, 1);
	}

	/** 是否是给AI用户送礼 */
	public boolean isAiUser() {
		return Cmp.ge(aiId, 1);
	}

}
